﻿using CTS.Com.Resources.Strings;

namespace CTS.Com.Domain.Helper
{
    /// <summary>
    /// NameHelper
    /// </summary>
    public static class NameHelper
    {
        /// <summary>
        /// Get name string from resource.
        /// </summary>
        /// <param name="nameId">Name id</param>
        /// <returns>Name string</returns>
        public static string GetNameString(string nameId)
        {
            // Local variable declaration
            var strNm = string.Empty;
            // Get string external
            var rms = ContextHelper.NameResources;
            for (int i = rms.Count - 1; i >= 0; i--) {
                var rm = rms[i];
                strNm = rm.GetString(nameId);
                if (strNm != null) {
                    return strNm;
                }
            }
            // Get string internal
            strNm = Names.ResourceManager.GetString(nameId);
            // Return value
            return strNm;
        }

        /// <summary>
        /// Get names from resource.
        /// </summary>
        /// <param name="messageId">Name id</param>
        /// <returns>Names</returns>
        public static object[] GetNames(params object[] param)
        {
            // Check null
            if (param == null) return null;
            // Get names
            var nameIds = new object[param.Length];
            var strNm = string.Empty;
            for (int i = 0; i < param.Length; i++) {
                nameIds[i] = param[i];
                // Check null
                if (param[i] == null) {
                    continue;
                }
                // CHhck type
                if (param[i].GetType() == typeof(string)) {
                    strNm = GetNameString(param[i].ToString());
                    if (strNm != null) {
                        nameIds[i] = strNm;
                    }
                }
            }
            // Return value
            return nameIds;
        }
    }
}
